<template>
  <div>
    <el-dialog
      title="新增权限"
      :visible.sync="addDiavisible"
      width="70%"
      :before-close="cancel"
      @opened="beforeopen"
    >
      <el-form
        :model="form"
        :rules="formRules"
        ref="formRef"
        label-width="140px"
      >
        <el-form-item label="权限名称" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="路径" prop="uri">
          <el-input v-model="form.uri"></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="order">
          <el-input v-model="form.order"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="addSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addOrUpdatePermission } from "@/api/family_doctor/family_doctor";
import { inputValidator } from "@/utils/validate";
export default {
  data() {
    return {
      addDiavisible: false,
      form: {
        name: "",
        uri: "",
        order: "",
        id:'',
        menuId:'',
      },
      formRules: {
        name: inputValidator,
        uri: inputValidator,
        order: inputValidator,
      },
    };
  },
  created() {},
  methods: {
    //关闭
    cancel() {
      for (var key in this.form) {
        this.form[key] = "";
      }
      this.$refs.formRef.clearValidate();
      this.$emit("transData");
      this.addDiavisible = false;
    },
    //弹窗渲染之前
    beforeopen() {},
    //提交
    addSubmit() {
       this.$refs.formRef.validate((valid) => {
        if (!valid) return this.$message.error("请输入必填项!");
        addOrUpdatePermission(this.form).then((res) => {
          if (res.code == "AA000000") {
            this.$message.success(res.msg);
          }
          this.cancel();
        });
      });
    },
    //供父组件调用函数
    openDialog(id) {
      this.form.menuId = id
      this.addDiavisible = true;
    },
  },
};
</script>